class Solution:
    def nthSuperUglyNumber(self, n: int, primes: list) -> int:
        count, length = 1, len(primes)
        count_list = [0 for i in range(length)]
        res_list = [1]
        for j in range(1, n):
            add_num = min(res_list[count_list[i]] * primes[i] for i in range(length))
            res_list.append(add_num)
            for i in range(length):
                if add_num % primes[i] == 0:
                    count_list[i] += 1
        return add_num


a = Solution()
print(a.nthSuperUglyNumber(n=12, primes=[2, 7, 13, 19]))
